﻿@inherits LayoutComponentBase
@layout BaseLayout
@inject NavigationManager NavigationManager
@inject IJSRuntime JSRuntime
@inject IOptions<WebsiteOptions> WebsiteOption

@Body

<footer>
    <div class="footer-body">
        <div>
            <h4>相关作品</h4>
            <ul>
                <li>
                    <a class="footer-link" href="@WebsiteOption.Value.BootstrapAdminLink" target="_blank">Bootstrap Admin</a>
                </li>
                <li>
                    <a class="footer-link" href="https://gitee.com/LongbowEnterprise/SliderCaptcha" target="_blank">滑块验证码</a>
                </li>
                <li>
                    <a class="footer-link" href="https://gitee.com/LongbowEnterprise/longbow-select" target="_blank">Longbow-select</a>
                </li>
                <li>
                    <a class="footer-link" href="https://gitee.com/LongbowEnterprise/longbow-validate" target="_blank">Longbow-validate</a>
                </li>
            </ul>
        </div>
        <div>
            <h4>友情链接</h4>
            <ul>
                <li>
                    <a class="footer-link" href="https://gitee.com/dotnetchina/Furion" target="_blank">Furion</a>
                </li>
                <li>
                    <a class="footer-link" href="http://ccflow.org" target="_blank">驰骋工作流</a>
                </li>
                <li>
                    <a class="footer-link" href="https://gitee.com/loogn/bulmarazor" target="_blank">Bulma</a>
                </li>
                <li>
                    <a class="footer-link" href="http://www.pearadmin.com" target="_blank">Pear Admin</a>
                </li>
                <li>
                    <a class="footer-link" href="https://ant-design-blazor.github.io/" target="_blank">Ant design of blazor</a>
                </li>
                <li>
                    <a class="footer-link" href="https://dotnet9.com/" target="_blank">Dotnet9</a>
                </li>
                <li>
                    <a class="footer-link" href="http://www.mrhuo.com/" target="_blank">M&J</a>
                </li>
            </ul>
        </div>
        <div>
            <h4>社区</h4>
            <ul>
                <li>
                    <div class="footer-link">贡献指南</div>
                </li>
                <li>
                    <div class="footer-link">加入我们</div>
                </li>
                <li>
                    <div class="footer-link">联系方式</div>
                </li>
            </ul>
        </div>
        <div>
            <h4>特别鸣谢</h4>
            <ul>
                <li>
                    <div class="footer-link">上海智通建设发展股份有限公司</div>
                </li>
            </ul>
        </div>
    </div>
    <div class="footer-info d-none d-sm-flex">
        <div>Powered by .NET @Version on Linux</div>
        <div class="ml-1">BB @BBVersion</div>
        <div class="d-flex flex-fill align-items-center justify-content-center">
            <a class="ml-3 d-none d-md-block" href="@WebsiteOption.Value.BootstrapBlazorLink" target="_blank">码云代码托管平台</a>
            <div class="mx-3 d-none d-md-block">
                <img alt="12377@2x" class="footer-logo mr-1" src="_content/BootstrapBlazor.Shared/images/12377@2x.png">
                <a href="https://12377.cn" target="_blank">违法和不良信息举报中心</a>
            </div>
            <div class="mr-3">
                <a href="http://www.beian.miit.gov.cn/" target="_blank">鲁ICP备19015061号</a>
            </div>
        </div>
        <div>
            <img alt="global" class="footer-lang" src="_content/BootstrapBlazor.Shared/images/global.svg" />
            <a @onclick:preventDefault @onclick="@(e => SetLang("zh-CN"))">简 体</a>
            /
            <a @onclick:preventDefault @onclick="@(e => SetLang("en-US"))">English</a>
        </div>
    </div>
</footer>

@code {
    private string Version => Environment.Version.ToString();

    private string BBVersion { get; set; } = "";

    private string SelectedCulture { get; set; } = CultureInfo.CurrentUICulture.Name;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        if (OperatingSystem.IsBrowser())
        {
            BBVersion = typeof(BootstrapComponentBase).Assembly.GetName().Version?.ToString() ?? "";
        }
        else
        {
            BBVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(BootstrapComponentBase).Assembly.Location).ProductVersion ?? "";
        }
    }

    private async Task SetLang(string cultureName)
    {
        if (OperatingSystem.IsBrowser())
        {
            if (cultureName != CultureInfo.CurrentCulture.Name)
            {
                await JSRuntime.InvokeVoidAsync(identifier: "$.blazorCulture.set", cultureName);
                var culture = new CultureInfo(cultureName);
                CultureInfo.CurrentCulture = culture;
                CultureInfo.CurrentUICulture = culture;

                NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
            }
        }
        else
        {
            // 使用 api 方式 适用于 Server-Side 模式
            if (SelectedCulture != cultureName)
            {
                var culture = cultureName;
                var uri = new Uri(NavigationManager.Uri).GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);
                var query = $"?culture={Uri.EscapeDataString(culture)}&redirectUri={Uri.EscapeDataString(uri)}";

                // use a path that matches your culture redirect controller from the previous steps
                NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true);
            }
        }
    }
}
